package com.resms.saas.consumer;

import com.resms.saas.consumer.service.EchoServiceConsumer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ImportResource;

/**
 * Hello world!
 *
 */
@SpringBootApplication
@ImportResource(locations = {"classpath:spring/consumer.xml"})
public class Consumer
{
    public static void main( String[] args )
    {
        System.out.println( "Dubbo Demo Consumer!" );
        ApplicationContext context = SpringApplication.run(Consumer.class,args);

//        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"classpath:spring/consumer.xml"});
//        context.start();

//        EchoService echoService = (EchoService)context.getBean("echoService"); // 获取远程服务代理
//        for(int i =1; i <= 100; i++) {
//            String hello = echoService.sayHello("world"); // 执行远程方法
//            System.out.println(hello); // 显示调用结果
//        }

        System.out.println("=======================================================================================");
        EchoServiceConsumer echoServiceConsumer = (EchoServiceConsumer) context.getBean("echoServiceConsumer");
        for(int i =1; i <= 100; i++) {
            String hello = echoServiceConsumer.doSayHello("world"); // 执行远程方法
            System.out.println(hello); // 显示调用结果
        }
    }
}
